<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>浮动-子元素对父元素的影响</title>
</head>
<style>
  .parent {
    border: 10px solid red;
    margin: 10px;
    /* height: 300px; */
  }

  .child {
    /* 会展示高度塌陷 */
    float: left;
    width: 100px;
    height: 100px;
    background-color: blue;
    margin: 10px;
  }

  /* .clear {
    1.2、清除浮动 clear: both;
  } */

  /* 2、使用伪元素清除 */
  /* .clear2::after {
    content: "";
    display: block;
    clear: both;
  } */

  /* 3、使用overflow */
  .clear2 {
    overflow: hidden;
  }

  /* 4、父级设置高度(不推荐) */
</style>

<body>
  <div class="parent">hello css</div>
  <div class="parent clear2">
    <div class="child">1</div>
    <div class="child">2</div>
    <div class="child">3</div>
    <div class="child">4</div>
  </div>
  <!-- 1、在浮动元素的下面增加一个空的div -->
  <div class="clear"></div>
  <div class="parent">hello css</div>

</body>

</html>